/*
 * banner图切换
 */

//自动循环播放
$(function() {
	$(".guo_list_down").hover(function(){
		$(this).children(".public_down").slideToggle(100);
	},function(){
		$(this).children(".public_down").slideToggle(100);
	});
	
	var bannerTime = setInterval(nextBannerImg, 5000);

	var bannerLi = $(".banner_img ul li");
	var banner = $(".banner_img");
	//循环添加banner图小按钮
	var str = "";
	for(var i = 0; i < bannerLi.length; i++) {
		str += "<li></li>";
	}
	$(".banner_img ol").html(str);
	var bannerBtnLi = $(".banner_img ol li");
	//banner图小按钮
	bannerBtnLi.mouseover(function() {
		clearInterval(bannerTime);
		bannerImg(bannerLi, $(this).index());
		bannerBtn(bannerBtnLi, $(this).index());
		bannerIndex = $(this).index();
	});
	var bannerIndex = 0;

	function nextBannerImg() {
		bannerIndex++;
		if(bannerIndex > bannerLi.length - 1) {
			bannerIndex = 0;
		}
		bannerImg(bannerLi, bannerIndex);
		bannerBtn(bannerBtnLi, bannerIndex);
	}

	function bannerImg(obj, num) {
		obj.eq(num).animate({ opacity: "1" }).siblings().animate({ opacity: "0" });
	}

	function bannerBtn(obj, num) {
		obj.eq(num).css("background", "#f00").siblings().css("background", "#fff");
		obj.eq(num).css("opacity", "1").siblings().css("opacity", "0.3");
	}
	//banner左右切换按钮
	$(".banner_btn .banner_btn_prev").click(function() {
		bannerIndex--;
		if(bannerIndex < 0) {
			bannerIndex = bannerLi.length - 1;
		}
		bannerImg(bannerLi, bannerIndex);
		bannerBtn(bannerBtnLi, bannerIndex);
	});
	$(".banner_btn .banner_btn_next").click(function() {
		nextBannerImg();
	});
	//放到左右切换按钮和图片上时停止循环播放
	$(".banner_btn .banner_btn_prev").hover(function() {
		clearInterval(bannerTime);
	}, function() {
		bannerTime = setInterval(nextBannerImg, 5000);
	});
	$(".banner_btn .banner_btn_next").hover(function() {
		clearInterval(bannerTime);
	}, function() {
		bannerTime = setInterval(nextBannerImg, 5000);
	});
	bannerLi.hover(function() {
		clearInterval(bannerTime);
	}, function() {
		bannerTime = setInterval(nextBannerImg, 5000);
	});

	/*
	 * 各个楼层选项卡
	 */
	$(".gm_floor_title li").mousemove(function() {
		$(this).addClass("cur").siblings().removeClass();
		var obj_floor_detail_r = $(this).parent().parent().siblings();
		var obj_floor_detail_r_c = obj_floor_detail_r.children().eq(1).children();
		$(obj_floor_detail_r_c).eq($(this).index()).fadeIn(200).siblings().fadeOut(200);
	});

	/*
	 * 楼层广告图
	 */

	var floorTime = setInterval(nextFloorImg, 5000);
	var floorLi = $(".floor1 .floor_detail_r .floor_wrap li");

	var floorBtnLi = $(".floor1 .floor_detail_r_wrap ol li");
	floorBtnLi.mouseover(function() {
		console.log($(this).index());
		clearInterval(floorTime);
		bannerImg(floorLi, $(this).index());
		bannerBtn(floorBtnLi, $(this).index());
		floorIndex = $(this).index();
	});

	var floorIndex = 0;

	function nextFloorImg() {
		floorIndex++;
		if(floorIndex > floorLi.length - 1) {
			floorIndex = 0;
		}
		bannerImg(floorLi, floorIndex);
		bannerBtn(floorBtnLi, floorIndex);
	};
	/*
	 * 动态添加选项卡的内容
	 */
	function createLi(obj, num) {
		var floorstr = "";
		for(var t = 1; t < num; t++) {
			floorstr += '<div class="floor_detail_r_main " data_tab="' + t + '"><div class="floor_detail_r_list2"><ul>';
			for(var m = 0; m < 10; m++) {
				floorstr += '<li><a href="#"><img src="img/f1_list2_' + t + '.jpg" alt="" /><p class="p_name">魅蓝5S 月光银 32G 全网通</p><p class="p_price"><span>&yen;</span>999.00</p></a></li>';

			}
			floorstr += "</ul></div></div>";
		}
		$(floorstr).appendTo(obj);
	}

	for(var n = 1; n < 5; n++) {
		createLi($(".floor" + n + " .floor_detail_r"), $(".floor" + n + " .gm_floor_title li").length);
	}

	
	//初始隐藏
	gohomeIsVisible();
	fixNavIsVisible();
	fixFloorIsVisible();
	fixFloor();
	//滚动条改变事件
	$(window).scroll(function() {
		gohomeIsVisible();
		fixNavIsVisible();
		fixFloorIsVisible();
	});
	//页面改变大小事件
	$(window).resize(function(){
		fixFloor();
	});
	/*
	 * 返回顶部 当整个页面相对滚动条顶部的偏移 > 171 显示
	 */
	function gohomeIsVisible(){
			if($("body").scrollTop() > 171) {
			$(".sidebar_gohome .sidebar_div").css("display", "block");
			$(".sidebar_gohome").hover(function() { $(".sidebar_gohome .sidebar_arrow").css("display", "block"); }, function() { $(".sidebar_gohome .sidebar_arrow").css("display", "none"); });
			$(".sidebar_gohome span").css("display", "none");
		} else {
			$(".sidebar_gohome .sidebar_div").css("display", "none");
			$(".sidebar_gohome .sidebar_arrow").css("display", "none");
			$(".sidebar_gohome span").css("display", "block");
			$(".sidebar_gohome").hover(function() { $(".sidebar_gohome .sidebar_arrow").css("display", "none"); }, function() {});
		}
	}
	$(".sidebar_gohome>a").click(function(){
		$("body").animate({scrollTop:"0px"});
	});
	$(".sidebar_gohome .sidebar_div").click(function(){
		$("body").animate({scrollTop:"0px"});
	});
	/*
	 *固定导航栏 当整个页面相对滚动条顶部的偏移 > 621 固定导航栏显示
	 */
	function fixNavIsVisible(){
		if($("body").scrollTop() > 621) {
			$(".fix_nav").css("display","block");
			$(".nav_all_type").addClass("nav_all_type_fix");
			$(".nav_hover span").css("display","block");
			$(".search").addClass("search_fix");
		}else{
			$(".fix_nav").css("display","none");
			$(".nav_all_type").removeClass("nav_all_type_fix");
			$(".nav_hover span").css("display","none");
			$(".search").removeClass("search_fix");
		}
	}
	
	/*
	 * 楼层列表 当整个页面相对滚动条顶部的偏移 > 171 固定导航栏显示
	 */
	function fixFloor(){
		var tt = ($("body").width() - parseFloat($("body").css("min-width")))/2;
		var ss = tt - parseFloat($(".fix_floor").css("width")) - 15;
		$(".fix_floor").css("left",ss+"px");
	}
	function fixFloorIsVisible(){
		if($("body").scrollTop() > 1432 && $("body").scrollTop() < 4000){
			$(".fix_floor").show();
		}else{
			$(".fix_floor").hide();
		}
	}
	

});